package com.alipay.traditionalbus;

import java.util.concurrent.CountDownLatch;

/**
 * Created by crazytime on 14-3-1.
 */
public class EventPublisher implements Runnable {

    private EventBus bus;

    private Long counts=1000L * 1000L * 100L;

    private int capacity;

    private Long[] events;

    private CountDownLatch readSignal;

    public EventPublisher(Long counts,int capacity,EventBus bus,CountDownLatch readSignal){
        this.counts=counts;
        this.capacity=capacity;
        this.events=new Long[capacity];
        this.bus=bus;
        this.readSignal=readSignal;
    }

    @Override
    public void run() {
        long current=0;
        while(current<counts){
            for(int i=0;i<capacity;i++){
                events[i]=new Long(i);
            }
            current=current+capacity;
            try {
                bus.postEvent(events);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        readSignal.countDown();
    }


}
